﻿using System;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;

using LTJ.Entity;
using LTJ.Common;
using LTJ.Common.Generic;
using LTJ.Config;
using LTJ.FrameWork;

namespace LTJ.WebPage.UserManage.rule
{
    /// <summary>
    /// 企业用户规则设置
    /// </summary>
    public partial class corpuserruleedit : UserPage
    {
        protected string opmode = SASRequest.GetString("opmode");
        protected int routeid = SASRequest.GetInt("routeid", 0);
        protected int rid = SASRequest.GetInt("rid", 0);
        protected RuleInfo rinfo = new RuleInfo();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void editrule_Click(object sender, EventArgs e)
        {
            rinfo.uid = SASRequest.GetInt("ajaxcorpuserdatalist_value", 0);
            rinfo.oid = 0;
            rinfo.rid = routeid;
            rinfo._20GP = price1.Text;
            rinfo._40GP = price2.Text;
            rinfo._40HQ = price3.Text;
            rinfo.rtype = 3;

            if (rinfo.uid == 0)
            {
                base.RegisterStartupScript("PAGETEMPLATE", "请选择用户！");
                return;
            }

            if (opmode == "add")
            {
                rinfo.id = Rules.CreateRules(rinfo.uid, rinfo.oid, rinfo.rtype, rinfo._20GP, rinfo._40GP, rinfo._40HQ, rinfo.rid, rinfo.port, rinfo.seacode);
                if (rinfo.id == -1)
                {
                    base.RegisterStartupScript("PAGETEMPLATE", "该航线规则已经存在，请在规则列表中查找进行修改！");
                    return;
                }

                OpLogs.LogRuleAdd(userid, username, companyinfo.id, rinfo.id, rinfo._20GP, rinfo._40GP, rinfo._40HQ);
            }
            else if (opmode == "edit")
            {
                Rules.UpdateRulePrice(rinfo.id, price1.Text, price2.Text, price3.Text);
                OpLogs.LogRuleEdit(userid, username, companyinfo.id, rinfo.id, rinfo._20GP, rinfo._40GP, rinfo._40HQ, "");
            }

            base.RegisterStartupScript("PAGE", "parent.document.getElementById('reclick').click();parent.Lightview.hide();");
        }

        #region Web 窗体设计器生成的代码

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            if (opmode == "edit")
            {
                rinfo = Rules.GetRuleInfoByID(rid);
                price1.Text = rinfo._20GP;
                price2.Text = rinfo._40GP;
                price3.Text = rinfo._40HQ;
            }

            editrule.Click += new EventHandler(editrule_Click);
        }

        #endregion
    }
}